package net.socket.client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class Client {

	public Client() {

		int remotePort = 10000;
		String remoteIp = "10.130.137.82";

		BufferedReader serverIn = null;
		PrintWriter serverOut = null;
		Socket socket = null;
		InetAddress rip = null;
		try {
			rip = InetAddress.getByName(remoteIp);
			socket = new Socket(rip, remotePort);
			
			serverIn = new BufferedReader(new InputStreamReader(
					socket.getInputStream()));
			serverOut = new PrintWriter(socket.getOutputStream(), true);

			//将控制台的用户输入数据写入out中，写回Server端
			BufferedReader fromConsoleUserData = new BufferedReader(new InputStreamReader(
					System.in));
			serverOut.println(fromConsoleUserData.readLine());
			
			//取得Server端返回的数据
			String fromServerData = serverIn.readLine();
			System.out.println(fromServerData);
			
			fromConsoleUserData.close();
			serverOut.close();
			serverIn.close();
			socket.close();
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) {
		new Client();

	}

}
